<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.hospinfoSTDsee"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
                            
    <section class="content-header">
        <h1><spring:message code="message.lable.hospinfoSTDsee"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.hospinfoStd"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            <%--  <form action="${ctx}/stdHospInfo/exportExcel.html" id="exportExcel" method="post" target="_blank"> --%>
            <form action="${ctx}/stdHospInfo/exportExcel.html" id="exportExcel" method="post" >
            <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.hospInfoxls"/>" />
                <div class="input" style="margin-top:-5px">
                <div class="textalign"><spring:message code="message.listForm.yiLiaoJiGouMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="hospName" name="hospName" placeholder="<spring:message code="message.listForm.yiLiaoJiGouMingCheng"/><spring:message code="message.list.fanXieGanPinYinMa"/>" maxlength="200"/>
                    </div>
                 <%-- <div class="textalign"><spring:message code="message.listForm.yiLiaoJiGouFenLei"/>：</div>
                    <div class="boxinput">
                         <select class="textinput"  id="hospClassify"  name="hospClassify"></select>
                    </div> --%>
                 <div class="textalign"><spring:message code="message.listForm.suoShuDiQu"/>：</div>
                    <div class="boxinput">
                       <table style="width:100%;">
                           <tr>
                              <td style="width:33%">
                                <select class="textinput" id="area1" disabled="disabled" name="area1"> 
                            <option value="${sysProvince}">${sysProvinceName}</option>
                        </select>
                              </td>
                              <td style="width:33%">   
                                <select class="textinput" id="area2" name="area2" ></select>
                                </td>
                              <td style="width:33%">
                                <select class="textinput" id="area3" name="area3" ></select>
                              </td>
                           </tr> 
                        </table>
                    </div>
                    <div class="textalign">是否零差率医院：</div>
	                    <div class="boxinput">
                        <select class="textinput" id="hospClassifys" name="hospClassifys">
                        	<option value="">请选择</option>
                            <option value="2">是</option>
                            <option value="1">否</option>
                        </select>
                    	</div>
                   
                    <div class="input" style="margin-top:3px">
                    	<div class="textalign"><spring:message code="message.lable.yiLiaoJiGouDengJi"/>：</div>
		                    <div class="boxinput">
		                         <select class="textinput"  id="hospType"  name="hospType"></select>
		                    </div>
	                    
	                      <div class="textalign">
                          <button id="selectHospinfo" type="button" class="btn btn-success btn-sm" onclick="search();"><spring:message code="message.button.seachSpacing"/></button>
                    	  </div>
                    </div>  
                    
                    
                    
                    <div hidden>
                        <div class="textalign" ><spring:message code="message.listForm.yiLiaoJiGouBianMa"/>：</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="hospCode"  name="hospCode" placeholder="<spring:message code="message.listForm.yiLiaoJiGouBianMa"/>" maxlength="100"/>
                        </div> 
                    </div>
                    <%--  <div class="textalign" style="display: none"><spring:message code="message.lable.status"/>：</div>
                    <div class="boxinput" style="display: none">
                        <select class="textinput"  id="status" name="status"> 
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="1"><spring:message code="message.button.start"/></option>
                            <option value="0"><spring:message code="message.button.stop"/></option>
                        </select>
                    </div> --%>
                   
                </div>
                <!-- <div class="input" style="margin-top:-5px">
                    
                </div> -->
            </form>
            </div>
          </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             <ms:btn url="/stdHospInfo/add.html"><a href="add.html?opType=0&areaId=${sysProvince}&areaName=${sysProvinceName}" class="btn btn-primary btn-sm"><spring:message code="message.button.addSpacing"/></a></ms:btn>
            <%--  <ms:btn url="/stdHospInfo/enable.html"> <label class="btn btn-default btn-sm" onclick="batchChangeStatus(1)"><spring:message code="message.button.startSpacing"/></label></ms:btn>
             <ms:btn url="/stdHospInfo/disable.html"><label class="btn btn-default btn-sm" onclick="batchChangeStatus(0)"><spring:message code="message.button.stopSpacing"/></label></ms:btn> --%>
       		<label onclick="exportExcel();" class="btn btn-primary btn-sm"><spring:message code="message.lable.daoChu"/></label>
        </div>
  
     <%--    <div id='coverdiv' style="Opacity:0.8;  position:fixed; left:0px; top:0px;width:100%;height:100%;"> </div>
        <div id='mydiv' style="border:0px solid #666666 ; padding:50px;text-align:center; position:absolute;background-image: url('${ctx }/lib/img/loading.gif'); background-repeat: no-repeat;">
        </div>   --%>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    
    <script type="text/javascript">
    
    //绑定回车
    $('#hospCode,#hospName,#hospClassify,#hospClassifys,#hospType,#area1,#area2,#area3,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectHospinfo').click();
        }
    }); 
  
    $("#hospName").focus();//加载页面光标在第一个查询框内
    
        function batchChangeStatus(status) {
            var msg = "";
            var url = ""; 
            if (status == 1){
                msg = "<spring:message code="message.button.start"/>";
                url = "${ctx}/stdHospInfo/disable.html";
            } else if (status == 0){
                msg = "<spring:message code="message.button.stop"/>";
                url = "${ctx}/stdHospInfo/enable.html";
            }
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return;
            }
            
            var str = "";
            var names = "";
            var count = 0;
                for (var i = 0;i < rowIds.length; i++){
                    var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
                    if (status == 1){
                        if (rowdata.status == "<spring:message code="message.button.stop"/>"){
                            names += rowdata.hospName+",";
                            str += rowIds[i]+",";
                            count++;
                        }
                    } else {
                        if (rowdata.status == "<spring:message code="message.button.start"/>"){
                            names += rowdata.hospName+",";
                            str += rowIds[i]+",";
                            count++;
                        }
                    }
                }
                if (names != ""){
                    names = names.substring(0,names.length-1);
                } else {
                    $.alert("<spring:message code="message.lable.ninXuanZe"/><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.lable.yiJingShi"/>"+msg+"<spring:message code="message.lable.zhuangTaiGTH"/>", "warn");
                    return;
                }
            
              //获取选中的ID及对应的名字（参数:jqgridId,名字列名，状态列名，当前操作即列表中显示的值），返回infos[0]是ID串，infos[1]是名字串
                var infos = batchSwitchStatus("gridlist","hospName","status",msg,"<spring:message code='message.listForm.yiLiaoJiGouMingCheng'/>");
                if ( !(infos instanceof Array)){
                    return;
                }
                
                  $.HN.message.confirm('<spring:message code="message.lable.OKYES"/>'+msg+'<spring:message code="message.lable.yiXia"/><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.lable.ma"/><br/>'+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) {
                if (e) {
                    if (str.length > 0){
                        str = str.substring(0,str.length-1);
                    }
                    var list = [];
                    for (var i=0; i<rowIds.length; i++) {
                        rowId = rowIds[i];
                        list.push(rowId);
                    }
                    $.post(url, {
                        "array" : json.jsonToString(list),"status":status
                    }, function(result) {
                        if (result.success) {
                            $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+''+count+"<spring:message code="message.lable.tiao"/><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.yanZheng.ganTanHao"/>", "success");
                            var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                            search(curpage);
                            
                        } else {
                            $.alert("<spring:message code="message.HN.alert.baoCunBai"/>","error");
                        }
                    }, "json");
                }
            });
        }
        
        function search(page) {
            var hospCode = $("#hospCode").val();
            var hospName = $("#hospName").val();
            var hospClassify = $("#hospClassify").val();
            var hospClassifys = $("#hospClassifys").val();
            var hospType = $("#hospType").val();
            var areaId = $("#area3").val();
            var status = $("#status").val();
            
            if("" == areaId){
                areaId = $("#area2").val().substring(0,4);
				if("" == areaId){
					areaId = $("#area1").val().substring(0,2);
				}
            } 

            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:{"hospCode":hospCode, "hospName":hospName, "area.areaid":areaId, "hospClassify": hospClassify, "hospClassifys": hospClassifys,"hospType":hospType, "status":status},
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/stdHospInfo/getHospInfoList.html",
                mtype: "post",
                postData:{"area.areaid":"${fn:substring(sysProvince, 0, 2)}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                    '<spring:message code="message.jqGrid.cz"/>',
                    '<spring:message code="message.listForm.yiLiaoJiGouBianMa"/>', 
                    '<spring:message code="message.listForm.yiLiaoJiGouMingCheng"/>', 
                    /* '<spring:message code="message.listForm.yiLiaoJiGouFenLei"/>',  */
                    '是否零差率医院',
                    '<spring:message code="message.listForm.zuZhiJiGouDaiMa"/>', 
                    '<spring:message code="message.listForm.suoShuDiQu"/>', 
                    '<spring:message code="message.listForm.yiLiaoJiGouDengJi"/>', 
                    '<spring:message code="message.lable.status"/>'
                ],
                colModel: [
                    { name: 'operate', width: 100, align:"center", sortable: false,
                        formatter : function(val, opts, rowdata) {
                            var str =  "<ms:btn url='/stdHospInfo/edit.html'><a href='edit.html?opType=1&hospId=" + rowdata.hospId + "' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
                            str += "<ms:btn url='/stdHospInfo/hospInfoDetail.html'><a href='hospInfoDetailPop.html?hospId=" + rowdata.hospId + "' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiangQing"/>'></a></ms:btn>";
                            str += "<ms:btn url='/stdHospInfo/hospInfoLogList.html'><a href='hospInfoLogList.html?hospId=" + rowdata.hospId + "&hospName="+rowdata.hospName+"&hospCode="+rowdata.hospCode+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
                        return str;
                    }},
                    { name: 'hospCode',hidden:true, width: 180, align:"center", sortable: false},
                    { name: 'hospName', width: 160, align:"left", sortable: false },
                    /* { name: 'hospType', width: 120, align:"left", sortable: false}, */
                    { name: 'hospClassify', width: 100, align:"center", sortable: false,
                    	formatter : function(val, opts, rowdata) {
                            var strSta = "";
                            if(rowdata.hospClassify == 1){
                                strSta += "否";
                            }else if(rowdata.hospClassify==2){
                                strSta += "是";
                            }
                            return strSta;
                        }},
                    { name: 'orgCode', width: 140, align:"center", sortable: false},
                    { name: 'arfullname', width: 200, align:"center", sortable: false},
                    { name: 'hospLevelName', width: 100, align:"center", sortable: false},
                    { name: 'status', hidden:true,width: 40, align: 'center', sortable: false,
                    	cellattr:function (rowId, val, rawObject, cm) {
                            if(val == '停用'){
                                return 'style="color:red"';
                            }
                        },

                        formatter : function(val, opts, rowdata) {
                            var strSta = "";
                            if(rowdata.status == 1){
                                strSta += "<spring:message code="message.button.start"/>";
                            }else{
                                strSta += "<spring:message code="message.button.stop"/>";
                            }
                            return strSta;
                        }
                    }
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "<spring:message code="message.list.hospinfoStdlist"/>",
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                
                jsonReader: {
                    id: "hospId",
                    repeatitems: false
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $("#area2").HNSelect({
                url: "${ctx}/selectController/getArea.html", 
                data: { ID: '${sysProvince}' },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
                func: function () {
                    $("#area3").HNSelect({
                        parent_selector: "#area2", 
                        url: "${ctx}/selectController/getArea.html", 
                        dataid: "ID", 
                        defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                        defaultselect: ""
                    });
                }
            });
            $("#hospClassify").HNSelect({
                url: "${ctx}/selectController/getArchiveType.html", 
                data: { classifyCode: "113" },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
            });
            $("#hospType").HNSelect({ 
                url: "${ctx}/selectController/getDicSys.html", 
                data: { 'ID' : "002" },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
            });

            $(window).trigger("resize");
        });
        
        
        function exportExcel(){
            
        	     $("#exportExcel").submit();
                               
            
        }
        
     /*   var cover =mydiv= null;
        window.onload = function() {
          cover=document.getElementById('coverdiv');
          cover.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
          cover.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px"
          cover.style.display = "none";
         
          mydiv = document.getElementById('mydiv');
          with (mydiv){
            style.width = document.documentElement.scrollHeight/2+"px";
            style.height = document.documentElement.scrollHeight/2+"px";
            style.left = (document.documentElement.scrollWidth - mydiv.offsetWidth)/2+"px";
            style.top = (document.documentElement.scrollHeight - mydiv.offsetHeight)/2+"px";
         
            style.display = "none";
          }
        };   */
        
        
      /*   function fileUp(){
            $('#exportExcel').modal({
                keyboard: true
            });
        } */
        
       /*  function exportExcel(){
    		$.HN.message.confirm('<spring:message code="message.lable.OKExport"/>&nbsp;<spring:message code="message.lable.hospInfoxls"/>&nbsp;<spring:message code="message.lable.ma"/>', '', '').on(function (e) {
	               if (e) {
	            	      
	            	  mydiv.style.display =cover.style.display = '';
	            	      $("#exportExcel").submit();
	            	    	   if(result.success){                                   
                                   $.HN.message.alert('导出成功！', '提示信息', 'success');
                                   
                                   mydiv.style.display =cover.style.display = 'none';
                                 
                               }else {
                                   $.HN.message.alert('导出失败！', '提示信息', 'success');
                               }

	               }
         	 }); 
         	
    	}   */
        
    	
      /*   $('#exportExcel').ajaxForm({ 
            dataType: 'json', 
            
            success: function(result) {
            	
            if(result.success) {
                $.HN.message.alert('导出成功！', '提示信息', 'success');
               
                
            }else{
                $.HN.message.alert('导出失败！', '提示信息', 'success');
            }
           }    
       }); */
       
       
       
     
    </script>
</body>
</html>